﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QunYing.Common;
using System.ServiceModel;
using System.ServiceModel.Description;

namespace QunYing.Common
{
   public class Services
    {
       public static void Open()
       {
           ServiceHost host = new ServiceHost(typeof(ImageOperatorGoods), new Uri(GlobalInfo.ServiceBaseAddr));
           NetTcpBinding bind = new NetTcpBinding();
           bind.MaxReceivedMessageSize = 1024 * 1024;
           bind.ReaderQuotas.MaxArrayLength = 1024 * 1024;
           bind.ReaderQuotas.MaxStringContentLength = 1024 * 1024;
           bind.Security.Mode = SecurityMode.None;
           host.AddServiceEndpoint(typeof(IImageOperator), bind, GlobalInfo.ServiceImageOperationGoods);
           host.Open();
           host = new ServiceHost(typeof(ImageOperatorDealerInfo), new Uri(GlobalInfo.ServiceBaseAddr));
           bind = new NetTcpBinding();
           bind.MaxReceivedMessageSize = 1024 * 1024;
           bind.ReaderQuotas.MaxArrayLength = 1024 * 1024;
           bind.ReaderQuotas.MaxStringContentLength = 1024 * 1024;
           bind.Security.Mode = SecurityMode.None;
           host.AddServiceEndpoint(typeof(IImageOperator), bind, GlobalInfo.ServiceImageOperationDealerInfo);
           host.Open();
           host = new ServiceHost(typeof(ImageOperatorVipInfo), new Uri(GlobalInfo.ServiceBaseAddr));
           bind = new NetTcpBinding();
           bind.MaxReceivedMessageSize = 1024 * 1024;
           bind.ReaderQuotas.MaxArrayLength = 1024 * 1024;
           bind.ReaderQuotas.MaxStringContentLength = 1024 * 1024;
           bind.Security.Mode = SecurityMode.None;
           host.AddServiceEndpoint(typeof(IImageOperator), bind, GlobalInfo.ServiceImageOperationVip);
           host.Open();

           bind = new NetTcpBinding();
           bind.MaxReceivedMessageSize = 1024 * 1024;
           bind.ReaderQuotas.MaxArrayLength = 1024 * 1024;
           bind.ReaderQuotas.MaxStringContentLength = 1024 * 1024;
           bind.ReceiveTimeout = TimeSpan.MaxValue;
           bind.Security.Mode = SecurityMode.None;
           bind.ReliableSession.InactivityTimeout =   TimeSpan.MaxValue;
           host = new ServiceHost(WarnInfoSeveice.Instance,  new Uri(GlobalInfo.ServiceBaseAddr));
           host.AddServiceEndpoint(typeof(IWarnInfoService), bind, GlobalInfo.ServiceWarnInfoProcess);
           var Behavior = host.Description.Behaviors.Find<ServiceThrottlingBehavior>();
           if (Behavior == null)
           {
               Behavior = new ServiceThrottlingBehavior();
               host.Description.Behaviors.Add(Behavior);
           }
           Behavior.MaxConcurrentSessions = 1024;
           Behavior.MaxConcurrentCalls = 1024;
           Behavior.MaxConcurrentInstances = 1024;
           host.Open();

           bind = new NetTcpBinding();
           bind.MaxReceivedMessageSize = 1024 * 1024;
           bind.ReaderQuotas.MaxArrayLength = 1024 * 1024;
           bind.ReaderQuotas.MaxStringContentLength = 1024 * 1024;
           bind.Security.Mode = SecurityMode.None;
           host = new ServiceHost(typeof(WarnInfoTransfer), new Uri(GlobalInfo.ServiceBaseAddr));
           host.AddServiceEndpoint(typeof(IWarnInfoReceived), bind, GlobalInfo.ServiceWarnInfoReceived);
           host.Open();

           bind = new NetTcpBinding();
           bind.MaxReceivedMessageSize = 1024 * 1024;
           bind.ReaderQuotas.MaxArrayLength = 1024 * 1024;
           bind.ReaderQuotas.MaxStringContentLength = 1024 * 1024;
           bind.ReceiveTimeout = TimeSpan.MaxValue;
           bind.Security.Mode = SecurityMode.None;
           bind.ReliableSession.InactivityTimeout = TimeSpan.MaxValue;
           host = new ServiceHost(OrderInfoSeveice.Instance, new Uri(GlobalInfo.ServiceBaseAddr));
           host.AddServiceEndpoint(typeof(IOrderInfoService), bind, GlobalInfo.ServiceOrderInfoProcess);
           var OrderBehavior = host.Description.Behaviors.Find<ServiceThrottlingBehavior>();
           if (OrderBehavior == null)
           {
               OrderBehavior = new ServiceThrottlingBehavior();
               host.Description.Behaviors.Add(OrderBehavior);
           }
           OrderBehavior.MaxConcurrentSessions = 1024;
           OrderBehavior.MaxConcurrentCalls = 1024;
           OrderBehavior.MaxConcurrentInstances = 1024;
           host.Open();

           bind = new NetTcpBinding();
           bind.MaxReceivedMessageSize = 1024 * 1024;
           bind.ReaderQuotas.MaxArrayLength = 1024 * 1024;
           bind.ReaderQuotas.MaxStringContentLength = 1024 * 1024;
           bind.Security.Mode = SecurityMode.None;
           host = new ServiceHost(typeof(OrderInfoTransfer), new Uri(GlobalInfo.ServiceBaseAddr));
           host.AddServiceEndpoint(typeof(IOrderInfoReceived), bind, GlobalInfo.ServiceOrderInfoReceived);
           host.Open();

           host = new ServiceHost(typeof(Online), new Uri(GlobalInfo.ServiceBaseAddr));
           bind = new NetTcpBinding();
           bind.MaxReceivedMessageSize = 1024 * 1024;
           bind.ReaderQuotas.MaxArrayLength = 1024 * 1024;
           bind.ReaderQuotas.MaxStringContentLength = 1024 * 1024;
           bind.Security.Mode = SecurityMode.None;
           host.AddServiceEndpoint(typeof(IOnline), bind, GlobalInfo.ServiceIsOnline);
           host.Open();
       }
    }
}
